let BASE_URL = "http://20.20.137.127:8080"
import axios from 'axios'

const service = axios.create({
    headers: {
        'Cache-Control': 'no-cache',
        'Pragma': 'no-cache'
    },
    baseURL: BASE_URL,
})

export function get(url, params) {
    const headerJSON = {
        "Content-Type": "application/x-www-form-urlencoded"
    };
    return new Promise((resolve, reject) => {
        service.get(url, {
            params: params
        }, { headers: headerJSON }).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err)
        });
    });
}

export function post(url, params) {

    return new Promise((resolve, reject) => {
        const headerJSON = {
            "Content-Type": "application/x-www-form-urlencoded"
        };
        service.post(url, JSON.stringify(params), { headerws: headerJSON })
            .then(res => {
                resolve(res);
            })
            .catch(err => {
                reject(err)
            });
    });
}

export function postJson(url, params) {
    return new Promise((resolve, reject) => {
        const headerJSON = {
            "Content-Type": "application/json"
        };
        service.post(url, JSON.stringify(params), { headers: headerJSON })
            .then((res) => {
                resolve(res);
            })
            .catch(err => {
                reject(err)
            });
    })
}
postJson(("/datasource/query_datasource_info", {
    "pageNum": 0,
    "pageSize": 0,
    "id": "12345",
    "condition": "测试任务",
    "inventoryUser": "user-001",
    "srcCname": "测试数据源",
    "srcEffStartDt": "2023-01-01 15:23:50",
    "srcEffEndDt": "2023-12-31 15:23:50"
})).then(res => {
    console.log(res)
}).catch(e => {
    console.error(e)
})